<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>物料顺序校验系统</title>
    <script src="/static/js/axios.min.js"></script>
    <link rel="stylesheet" href="/static/css/all.min.css">
    <style>
        :root {
            --primary: #3498db;
            --success: #2ecc71;
            --danger: #e74c3c;
            --warning: #f39c12;
            --dark: #2c3e50;
            --light: #ecf0f1;
            --gray: #95a5a6;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
            background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
            color: #333;
            line-height: 1.5;
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
        }

        header {
            text-align: center;
            margin-bottom: 20px;
            padding: 15px;
            background: linear-gradient(90deg, var(--primary) 0%, #2980b9 100%);
            border-radius: 10px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
            color: white;
        }

        h1 {
            font-size: 1.8rem;
            margin-bottom: 5px;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }

        .card {
            background: white;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
            padding: 20px;
            margin-bottom: 20px;
            transition: transform 0.2s ease;
        }

        .section-title {
            font-size: 1.2rem;
            font-weight: 600;
            margin-bottom: 15px;
            color: var(--dark);
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .input-group {
            position: relative;
            margin-bottom: 15px;
        }

        .input-field {
            width: 100%;
            padding: 12px 15px;
            border: 2px solid #e1e5eb;
            border-radius: 8px;
            font-size: 15px;
            transition: all 0.3s ease;
            background: #f8fafc;
        }

        .input-field:focus {
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
            outline: none;
            background: white;
        }

        .input-field::placeholder {
            color: #a0aec0;
        }

        .btn {
            padding: 12px 15px;
            background: var(--primary);
            color: white;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-size: 15px;
            font-weight: 600;
            width: 100%;
            transition: all 0.3s ease;
        }

        .btn:hover {
            background: #2980b9;
        }

        .btn-reset {
            background: var(--danger);
        }

        .btn-reset:hover {
            background: #c0392b;
        }

        .flex-row {
            display: flex;
            gap: 12px;
            margin-top: 12px;
        }

        .flex-row .btn {
            flex: 1;
        }

        .status-bar {
            background: #f1f8ff;
            padding: 12px 15px;
            border-radius: 8px;
            margin-bottom: 15px;
            border-left: 3px solid var(--primary);
        }

        .status-item {
            display: flex;
            justify-content: space-between;
            margin-bottom: 5px;
            font-size: 14px;
        }

        .status-label {
            font-weight: 600;
            color: #4a5568;
        }

        .status-value {
            font-weight: 600;
            color: var(--dark);
        }

        .progress-container {
            margin: 10px 0;
        }

        .progress-bar {
            height: 10px;
            background: #e2e8f0;
            border-radius: 5px;
            overflow: hidden;
        }

        .progress-fill {
            height: 100%;
            background: linear-gradient(90deg, var(--success) 0%, #27ae60 100%);
            border-radius: 5px;
            transition: width 0.5s ease;
        }

        .progress-text {
            text-align: right;
            font-size: 13px;
            color: var(--gray);
            margin-top: 3px;
            font-weight: 500;
        }

        .material-list {
            margin: 15px 0;
            border-radius: 8px;
            overflow: hidden;
            border: 1px solid #e2e8f0;
        }

        .material-item {
            padding: 8px 12px;
            display: flex;
            align-items: center;
            min-height: 40px;
            border-bottom: 1px solid #edf2f7;
            transition: background-color 0.3s ease;
        }

        .material-item:last-child {
            border-bottom: none;
        }

        .material-sort {
            width: 28px;
            height: 28px;
            background: #ebf8ff;
            border: 1px solid #bee3f8;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            font-size: 13px;
            margin-right: 12px;
            flex-shrink: 0;
        }

        .material-info {
            flex: 1;
            display: flex;
            align-items: center;
            gap: 10px;
            overflow: hidden;
        }

        .material-name {
            font-weight: 600;
            font-size: 14px;
            color: var(--dark);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            flex: 2;
        }

        .material-code {
            font-size: 13px;
            color: #4a5568;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            flex: 1;
        }

        .material-status {
            padding: 4px 10px;
            border-radius: 15px;
            font-size: 12px;
            font-weight: 600;
            margin-left: 10px;
            flex-shrink: 0;
        }

        .scanned {
            background-color: #dcfce7;
            color: #166534;
        }

        .current {
            background-color: #dbeafe;
            color: #1e40af;
        }

        .error {
            background-color: #fee2e2;
            color: #b91c1c;
        }

        .validation-section {
            position: relative;
        }

        .validation-result {
            margin-top: 15px;
            padding: 15px;
            border-radius: 8px;
            font-weight: 600;
            font-size: 14px;
            text-align: center;
            display: none;
        }

        .success {
            background-color: #dcfce7;
            color: #166534;
            border-left: 3px solid var(--success);
        }

        .error {
            background-color: #fee2e2;
            color: #b91c1c;
            border-left: 3px solid var(--danger);
        }

        .hidden {
            display: none;
        }

        .system-info {
            text-align: center;
            margin-top: 20px;
            color: var(--gray);
            font-size: 13px;
        }

        .scan-animation {
            position: relative;
            overflow: hidden;
        }

        .scan-line {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 2px;
            background: linear-gradient(90deg, transparent, rgba(52, 152, 219, 0.7), transparent);
            animation: scan 2s infinite;
        }

        @keyframes scan {
            0% {
                transform: translateY(0);
            }
            100% {
                transform: translateY(100%);
            }
        }

        .material-item.current {
            background-color: #f0f9ff;
            animation: pulse 2s infinite;
        }

        @keyframes pulse {
            0% {
                box-shadow: 0 0 0 0 rgba(52, 152, 219, 0.2);
            }
            70% {
                box-shadow: 0 0 0 5px rgba(52, 152, 219, 0);
            }
            100% {
                box-shadow: 0 0 0 0 rgba(52, 152, 219, 0);
            }
        }

        .error-item .material-sort {
            background: #fee2e2;
            border-color: #fecaca;
        }

        .icon {
            width: 20px;
            text-align: center;
        }

        .debug-info {
            background: #f8f9fa;
            padding: 10px;
            border-radius: 8px;
            font-size: 12px;
            color: #6c757d;
            margin-top: 10px;
            display: none;
        }

        .debug-title {
            font-weight: bold;
            margin-bottom: 5px;
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1><i class="fas fa-boxes"></i> 物料顺序校验系统</h1>
            <p>确保装配顺序准确无误</p>
        </header>

        <!-- 扫描单号区域 -->
        <div class="card">
            <div class="section-title">
                <i class="fas fa-barcode icon"></i>
                <span>1. 扫描单号</span>
            </div>
            <div class="input-group">
                <input type="text" id="orderInput" class="input-field" placeholder="请扫描或输入单号" autocomplete="off" autofocus>
            </div>
            <div class="flex-row">
                <button class="btn" onclick="scanOrder(false)">
                    <i class="fas fa-search"></i> 查询订单
                </button>
                <button class="btn btn-reset" onclick="resetValidation()">
                    <i class="fas fa-redo"></i> 重新开始
                </button>
            </div>
        </div>

        <!-- 订单信息展示 -->
        <div class="card hidden" id="orderInfo">
            <div class="section-title">
                <i class="fas fa-clipboard-list icon"></i>
                <span>订单信息</span>
            </div>
            <div class="status-bar">
                <div class="status-item">
                    <span class="status-label">单号:</span>
                    <span class="status-value" id="orderNoDisplay">-</span>
                </div>
                <div class="status-item">
                    <span class="status-label">状态:</span>
                    <span class="status-value" id="orderStatus">进行中</span>
                </div>
                <div class="status-item">
                    <span class="status-label">下一项:</span>
                    <span class="status-value" id="nextOrderDisplay">-</span>
                </div>
            </div>

            <div class="progress-container">
                <div class="progress-bar">
                    <div class="progress-fill" id="progressFill" style="width: 0%"></div>
                </div>
                <div class="progress-text">
                    <span id="scannedCount">0</span> / <span id="totalCount">0</span> 项物料已完成
                </div>
            </div>

            <div class="section-title">
                <i class="fas fa-list-ol icon"></i>
                <span>物料清单</span>
            </div>
            <div id="materialList" class="material-list"></div>

            <div class="debug-info" id="debugInfo">
                <div class="debug-title">调试信息：</div>
                <div id="debugContent">无</div>
            </div>
        </div>

        <!-- 扫描SN区域 -->
        <div class="card hidden validation-section" id="scanSnSection">
            <div class="section-title">
                <i class="fas fa-qrcode icon"></i>
                <span>2. 扫描SN码</span>
            </div>
            <div class="scan-animation">
                <div class="input-group">
                    <input type="text" id="snInput" class="input-field" placeholder="请扫描或输入SN码" autocomplete="off">
                    <div class="scan-line"></div>
                </div>
            </div>
            <button class="btn" onclick="scanSN()">
                <i class="fas fa-check-circle"></i> 验证SN码
            </button>
            <div id="validationResult" class="validation-result"></div>
        </div>

        <div class="system-info">
            <p><i class="fas fa-cog"></i> 物料顺序校验系统 v2.3 | 生产环境</p>
        </div>
    </div>

    <script>
        // 全局变量存储当前订单和物料信息
        let currentOrder = null;
        let currentMaterialInfo = {
            sort: null,
            code: null,
            name: null
        };

        // 自动聚焦输入框
        document.getElementById('orderInput').focus();

        // 扫描订单函数
        function scanOrder(reset) {
            let orderNo = document.getElementById('orderInput').value.trim();

            if (reset && currentOrder) {
                orderNo = currentOrder;
            } else if (!orderNo) {
                showError("请输入单号");
                return;
            }

            const formData = new FormData();
            formData.append('order_no', orderNo);
            formData.append('reset', reset.toString());

            axios.post('/scan_order', formData)
                .then(response => {
                    if (response.data.success) {
                        currentOrder = orderNo;

                        // 清空单号输入框（仅在非重置操作时）
                        if (!reset) {
                            document.getElementById('orderInput').value = '';
                        }

                        displayOrderInfo(response.data);
                        document.getElementById('snInput').focus();

                        if (reset) {
                            showSuccess("已重置单号验证状态，重新开始验证");
                        }
                    } else {
                        showError(response.data.message);
                    }
                })
                .catch(error => {
                    showError('请求失败: ' + error.message);
                });
        }

        // 重置验证函数
        function resetValidation() {
            if (!currentOrder) {
                const orderNo = document.getElementById('orderInput').value.trim();
                if (!orderNo) {
                    showError("请输入单号");
                    return;
                }
                scanOrder(true);
            } else {
                scanOrder(true);
            }
        }

        // 显示订单信息
        function displayOrderInfo(data) {
            document.getElementById('orderNoDisplay').textContent = data.order_no;
            document.getElementById('scannedCount').textContent = data.scanned_count || 0;
            document.getElementById('totalCount').textContent = data.total_count || 0;

            const progress = data.total_count ? Math.round((data.scanned_count / data.total_count) * 100) : 0;
            document.getElementById('progressFill').style.width = `${progress}%`;

            const orderStatus = document.getElementById('orderStatus');
            if (data.next_order === null) {
                orderStatus.textContent = "已完成";
                orderStatus.style.color = "var(--success)";
            } else {
                orderStatus.textContent = "进行中";
                orderStatus.style.color = "var(--primary)";
            }

            const materialList = document.getElementById('materialList');
            materialList.innerHTML = '';

            data.items.forEach(item => {
                const itemDiv = document.createElement('div');
                itemDiv.className = 'material-item';

                const sortSpan = document.createElement('div');
                sortSpan.className = 'material-sort';
                sortSpan.textContent = item.sort;

                const infoDiv = document.createElement('div');
                infoDiv.className = 'material-info';

                const nameSpan = document.createElement('div');
                nameSpan.className = 'material-name';
                nameSpan.textContent = item.material_name;
                nameSpan.title = item.material_name;

                const codeSpan = document.createElement('div');
                codeSpan.className = 'material-code';
                codeSpan.textContent = item.material_code;
                codeSpan.title = item.material_code;

                infoDiv.appendChild(nameSpan);
                infoDiv.appendChild(codeSpan);

                const statusSpan = document.createElement('div');
                statusSpan.className = 'material-status';

                // 修复：优先判断当前待扫描状态
                if (item.status === "当前待扫描") {
                    statusSpan.classList.add('current');
                    statusSpan.textContent = '待扫描';
                    itemDiv.classList.add('current');
                }
                else if (item.status === "验证成功") {
                    statusSpan.classList.add('scanned');
                    statusSpan.textContent = '验证成功';
                } else if (item.status === "验证失败") {
                    statusSpan.classList.add('error');
                    statusSpan.textContent = '验证失败';
                    itemDiv.classList.add('error-item');
                } else {
                    statusSpan.textContent = '等待扫描';
                }

                itemDiv.appendChild(sortSpan);
                itemDiv.appendChild(infoDiv);
                itemDiv.appendChild(statusSpan);
                materialList.appendChild(itemDiv);
            });

            // 更新下一项显示
            let nextText = "所有物料已完成扫描";
            if (data.next_order) {
                // 尝试从物料列表中获取当前物料名称
                let currentName = "未知物料";
                for (const item of data.items) {
                    if (item.sort == data.next_order) {
                        currentName = item.material_name;
                        break;
                    }
                }

                nextText = `序号: ${data.next_order} - ${currentName}`;
            }
            document.getElementById('nextOrderDisplay').textContent = nextText;

            // 存储当前物料信息
            if (data.next_order !== null) {
                currentMaterialInfo = {
                    sort: data.next_order,
                    code: data.current_material,
                    name: data.current_material_name
                };
            } else {
                currentMaterialInfo = {
                    sort: null,
                    code: null,
                    name: null
                };
            }

            // 显示调试信息
            document.getElementById('debugContent').innerHTML =
                `当前物料: ${currentMaterialInfo.sort} | ${currentMaterialInfo.code} | ${currentMaterialInfo.name}`;
            document.getElementById('debugInfo').style.display = 'block';

            // 显示订单信息和SN扫描区域
            document.getElementById('orderInfo').classList.remove('hidden');
            document.getElementById('scanSnSection').classList.remove('hidden');
        }

        // 扫描SN函数
        function scanSN() {
            const sn = document.getElementById('snInput').value.trim();
            if (!sn) {
                showError("请输入SN码");
                return;
            }

            if (!currentMaterialInfo.sort || !currentMaterialInfo.code) {
                showError("没有需要扫描的物料或未获取到物料信息");
                return;
            }

            const btn = document.querySelector('#scanSnSection button');
            const snInput = document.getElementById('snInput');
            btn.disabled = true;
            snInput.disabled = true;

            const formData = new FormData();
            formData.append('order_no', currentOrder);
            formData.append('sn', sn);
            formData.append('current_sort', currentMaterialInfo.sort);
            formData.append('current_material', currentMaterialInfo.code);

            axios.post('/scan_sn', formData)
                .then(response => {
                    const resultEl = document.getElementById('validationResult');
                    resultEl.style.display = 'block';

                    if (response.data.success) {
                        const is_valid = response.data.is_valid;
                        if (is_valid) {
                            resultEl.className = 'validation-result success';
                            resultEl.innerHTML = '<i class="fas fa-check-circle"></i> 验证成功: ' + response.data.message;
                            playSound('success');
                        } else {
                            resultEl.className = 'validation-result error';
                            resultEl.innerHTML = '<i class="fas fa-exclamation-circle"></i> 验证失败: ' + response.data.message;
                            playSound('error');
                        }

                        // 更新当前验证的物料状态
                        updateSingleMaterialStatus(currentMaterialInfo.sort, is_valid);

                        // 更新当前物料信息为下一个
                        currentMaterialInfo = {
                            sort: response.data.next_order,
                            code: response.data.next_material_code,
                            name: response.data.next_material_name
                        };

                        // 更新下一项显示
                        const nextOrderDisplay = document.getElementById('nextOrderDisplay');
                        if (currentMaterialInfo.sort) {
                            nextOrderDisplay.textContent = `序号: ${currentMaterialInfo.sort} - ${currentMaterialInfo.name}`;
                        } else {
                            nextOrderDisplay.textContent = "所有物料已完成扫描";
                        }

                        // 更新进度计数和进度条
                        updateProgress();

                        // 隐藏验证结果信息
                        setTimeout(() => {
                            resultEl.style.display = 'none';
                        }, 2000);
                    } else {
                        resultEl.className = 'validation-result error';
                        resultEl.innerHTML = '<i class="fas fa-exclamation-triangle"></i> ' + response.data.message;
                        playSound('error');
                    }
                })
                .catch(error => {
                    const resultEl = document.getElementById('validationResult');
                    resultEl.className = 'validation-result error';
                    resultEl.style.display = 'block';
                    resultEl.innerHTML = '<i class="fas fa-exclamation-triangle"></i> 请求失败: ' + error.message;
                    playSound('error');
                })
                .finally(() => {
                    snInput.value = '';
                    btn.disabled = false;
                    snInput.disabled = false;
                    snInput.focus();
                });
        }
        function scanSN() {
    const sn = document.getElementById('snInput').value.trim();
    if (!sn) {
        showError("请输入SN码");
        return;
    }

    if (!currentMaterialInfo.sort || !currentMaterialInfo.code) {
        showError("没有需要扫描的物料或未获取到物料信息");
        return;
    }

    const btn = document.querySelector('#scanSnSection button');
    const snInput = document.getElementById('snInput');
    btn.disabled = true;
    snInput.disabled = true;

    const formData = new FormData();
    formData.append('order_no', currentOrder);
    formData.append('sn', sn);
    formData.append('current_sort', currentMaterialInfo.sort);
    formData.append('current_material', currentMaterialInfo.code);

    axios.post('/scan_sn', formData)
        .then(response => {
            const resultEl = document.getElementById('validationResult');
            resultEl.style.display = 'block';

            if (response.data.success) {
                const is_valid = response.data.is_valid;
                if (is_valid) {
                    resultEl.className = 'validation-result success';
                    resultEl.innerHTML = '<i class="fas fa-check-circle"></i> 验证成功: ' + response.data.message;
                    playSound('success');
                } else {
                    resultEl.className = 'validation-result error';
                    resultEl.innerHTML = '<i class="fas fa-exclamation-circle"></i> 验证失败: ' + response.data.message;
                    playSound('error');
                }

                // 更新当前验证的物料状态
                updateSingleMaterialStatus(currentMaterialInfo.sort, is_valid);

                // 更新当前物料信息为下一个
                currentMaterialInfo = {
                    sort: response.data.next_order,
                    code: response.data.next_material_code,
                    name: response.data.next_material_name
                };

                // 更新下一项显示
                const nextOrderDisplay = document.getElementById('nextOrderDisplay');
                if (currentMaterialInfo.sort) {
                    nextOrderDisplay.textContent = `序号: ${currentMaterialInfo.sort} - ${currentMaterialInfo.name}`;
                } else {
                    nextOrderDisplay.textContent = "所有物料已完成扫描";
                }

                // 更新进度计数和进度条
                updateProgress();

                // 隐藏验证结果信息
                setTimeout(() => {
                    resultEl.style.display = 'none';
                }, 2000);
            } else {
                resultEl.className = 'validation-result error';
                resultEl.innerHTML = '<i class="fas fa-exclamation-triangle"></i> ' + response.data.message;
                playSound('error');
            }
        })
        .catch(error => {
            const resultEl = document.getElementById('validationResult');
            resultEl.className = 'validation-result error';
            resultEl.style.display = 'block';
            resultEl.innerHTML = '<i class="fas fa-exclamation-triangle"></i> 请求失败: ' + error.message;
            playSound('error');
        })
        .finally(() => {
            snInput.value = '';
            btn.disabled = false;
            snInput.disabled = false;
            snInput.focus();
        });
}
        function updateSingleMaterialStatus(sort, isValid) {
            const materialItems = document.querySelectorAll('.material-item');
            materialItems.forEach(item => {
                const sortSpan = item.querySelector('.material-sort');
                if (sortSpan && parseInt(sortSpan.textContent) === parseInt(sort)) {
                    const statusSpan = item.querySelector('.material-status');

                    // 清除现有状态类
                    statusSpan.classList.remove('scanned', 'error', 'current');
                    item.classList.remove('current', 'error-item');

                    if (isValid) {
                        statusSpan.classList.add('scanned');
                        statusSpan.textContent = '验证成功';
                    } else {
                        statusSpan.classList.add('error');
                        statusSpan.textContent = '验证失败';
                        item.classList.add('error-item');
                    }
                }
            });
        }
        function updateProgress() {
            const scannedCountEl = document.getElementById('scannedCount');
            const totalCount = parseInt(document.getElementById('totalCount').textContent);

            scannedCountEl.textContent = parseInt(scannedCountEl.textContent) + 1;

            const scannedCount = parseInt(scannedCountEl.textContent);
            const progress = totalCount ? Math.round((scannedCount / totalCount) * 100) : 0;
            document.getElementById('progressFill').style.width = `${progress}%`;
        }
        // 更新物料状态函数 - 添加失败状态处理
        function updateMaterialStatus(sort, isValid) {
            const materialItems = document.querySelectorAll('.material-item');
            materialItems.forEach(item => {
                const sortSpan = item.querySelector('.material-sort');
                if (sortSpan && parseInt(sortSpan.textContent) === parseInt(sort)) {
                    const statusSpan = item.querySelector('.material-status');

                    // 清除现有状态类
                    statusSpan.classList.remove('scanned', 'error', 'current');
                    item.classList.remove('current', 'error-item');

                    // 根据验证结果更新状态
                    if (isValid) {
                        statusSpan.classList.add('scanned');
                        statusSpan.textContent = '验证成功';
                    } else {
                        statusSpan.classList.add('error');
                        statusSpan.textContent = '验证失败';
                        item.classList.add('error-item');
                    }
                }
            });

            // 更新进度计数
            const scannedCountEl = document.getElementById('scannedCount');
            const totalCount = parseInt(document.getElementById('totalCount').textContent);

            // 无论成功还是失败，都增加计数
            scannedCountEl.textContent = parseInt(scannedCountEl.textContent) + 1;

            // 更新进度条
            const scannedCount = parseInt(scannedCountEl.textContent);
            const progress = totalCount ? Math.round((scannedCount / totalCount) * 100) : 0;
            document.getElementById('progressFill').style.width = `${progress}%`;

            // 更新下一项显示
            const nextOrderDisplay = document.getElementById('nextOrderDisplay');
            if (currentMaterialInfo.sort) {
                nextOrderDisplay.textContent = `序号: ${currentMaterialInfo.sort} - ${currentMaterialInfo.name}`;
            } else {
                nextOrderDisplay.textContent = "所有物料已完成扫描";
            }
        }
        // 播放提示音
        function playSound(type) {
            const audio = new Audio();
            audio.src = type === 'success' ?
                'https://www.soundjay.com/buttons/sounds/button-09.mp3' :
                'https://www.soundjay.com/buttons/sounds/button-10.mp3';
            audio.play().catch(e => console.log("音频播放失败:", e));
        }

        // 显示错误消息
        function showError(message) {
            const resultEl = document.getElementById('validationResult');
            if (resultEl) {
                resultEl.className = 'validation-result error';
                resultEl.style.display = 'block';
                resultEl.innerHTML = '<i class="fas fa-exclamation-circle"></i> ' + message;
                playSound('error');

                setTimeout(() => {
                    resultEl.style.display = 'none';
                }, 3000);
            } else {
                alert(message);
            }
        }

        // 显示成功消息
        function showSuccess(message) {
            const resultEl = document.getElementById('validationResult');
            if (resultEl) {
                resultEl.className = 'validation-result success';
                resultEl.style.display = 'block';
                resultEl.innerHTML = '<i class="fas fa-check-circle"></i> ' + message;
                playSound('success');

                setTimeout(() => {
                    resultEl.style.display = 'none';
                }, 3000);
            } else {
                alert(message);
            }
        }
        function refreshOrderInfo() {
            if (!currentOrder) return;

            const formData = new FormData();
            formData.append('order_no', currentOrder);
            formData.append('reset', 'false');

            axios.post('/scan_order', formData)
                .then(response => {
                    if (response.data.success) {
                        displayOrderInfo(response.data);
                    }
                })
                .catch(error => {
                    console.error('刷新失败:', error);
                });
        }
        // 输入框回车事件
        document.getElementById('orderInput').addEventListener('keypress', function(e) {
            if (e.key === 'Enter') scanOrder(false);
        });

        document.getElementById('snInput').addEventListener('keypress', function(e) {
            if (e.key === 'Enter') scanSN();
        });
    </script>
</body>
</html>